﻿// Declare variables
var a;
var p;

// Create my album collection
var albums = new Array();


// ********* Album 1 ***********//

// Create instance of album 1 and name it
a = new Album("My Album");

// Create and add photos to the album
p = new Photo("Pic of world", "images/thumbs/world.jpg", "images/photos/world.jpg");
a.addPhoto(p);

p = new Photo("Pic of world 2", "images/thumbs/world.jpg", "images/photos/world.jpg");
a.addPhoto(p);

// Add my album to the albums collection
albums.push(a);

// ********* Album 2 ***********//

// Create instance of album 1 and name it
a = new Album("My Album 2");

// Create and add photos to the album
p = new Photo("Pic of world", "images/thumbs/world.jpg", "images/photos/world.jpg");
a.addPhoto(p);

p = new Photo("Pic of world 2", "images/thumbs/world.jpg", "images/photos/world.jpg");
a.addPhoto(p);

// Add my album to the albums collection
albums.push(a);





// ***************** Add albums to our html *******************//

var albumContainer = document.getElementById("container");

for(var i=0; i<albums.length; i++){
	
	// Create a header for the album
	var h1 = document.createElement('h1');
	h1.innerHTML = albums[i].title;
	
	// Create album ul that contains photos for that album
	var ul = document.createElement('ul');
	ul.setAttribute('id','album-'+i);
	
	// Hold a reference to the photos within the current album iteration
	var curAlbumPhotos = albums[i].photos;
	
	// Loop each photo in the album
	for(var j=0; j<curAlbumPhotos.length; j++){
		
		// Create a li and image for each photo
		var li = document.createElement('li');
		var img = document.createElement('img');
		img.setAttribute('src',curAlbumPhotos[j].image);
		img.setAttribute('class','album-photo');
		
		// Append the image to the li and the li to the ul
		li.appendChild(img);
		ul.appendChild(li);
	}	
	
	// Append each album header and photo list to the container
	albumContainer.appendChild(h1);
	albumContainer.appendChild(ul);
}






